﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace robotics_ex_1_3
{
    class Line
    {
        public Point StartPoint;
        public Point EndPoint;
        public double Angle;
        public double OrigTan;
        public bool IsVertical;
        public bool IsHorizontal;

        public Line(Point startPoint, Point endPoint)
        {
            StartPoint = startPoint;
            EndPoint = endPoint;
            Angle = calcAngle();
            Console.WriteLine(string.Format("New line from ({0},{1}) to ({2},{3}) with angle of {4}",startPoint.X, startPoint.Y,endPoint.X,endPoint.Y,Angle));

            IsVertical = (startPoint.X == endPoint.X) ? true : false;
            IsHorizontal = (startPoint.Y == endPoint.Y) ? true : false;
        }

        private double calcAngle()
        {
            if (StartPoint.X != EndPoint.X)
            {
                OrigTan = (EndPoint.Y - StartPoint.Y) / (EndPoint.X - StartPoint.X);
                double angle = Math.Atan(OrigTan);

                if (EndPoint.X < StartPoint.X)
                {
                    angle -= Math.PI;
                }

                angle -= Math.PI / 2;

                if (angle < 0)
                {
                    angle += 2 * Math.PI;
                }

                return angle;
            }

            if (StartPoint.Y >= EndPoint.Y)
            {
                return Math.PI;
            }

            return 0;
        }

        public override string ToString()
        {
            return string.Format("({0},{1}) ----> ({2},{3})", StartPoint.X, StartPoint.Y, EndPoint.X, EndPoint.Y);
        }

    }
}
